//
//  ZStatusRetweetView.m
//  OC-weibo
//
//  Created by zero on 17/3/24.
//  Copyright © 2017年 zero. All rights reserved.
//

#import "ZStatusRetweetView.h"
#import "ZCollectionView.h"

@interface ZStatusRetweetView()

@property (nonatomic,weak)UILabel *labContent;

@property (nonatomic,weak)ZCollectionView *collectionView;

//  记录约束
@property (nonatomic,strong)MASConstraint *constraint;

@end

@implementation ZStatusRetweetView

#pragma mark
#pragma mark - 重写init方法
- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        //  布局
        
        [self setupUI];
    }
    
    return self;
}

#pragma mark
#pragma mark - 布局
- (void)setupUI{
    
    UILabel *textLabel = [UILabel z_labelWithText:@"转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博转发的微博" andFontSize:14 andColor:[UIColor blackColor]];
    
    self.labContent = textLabel;
    
    textLabel.preferredMaxLayoutWidth = 355;
    textLabel.numberOfLines = 0;
    
    [self addSubview:textLabel];
    
    //  约束
    [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self);
        
        make.leading.equalTo(self).offset(8);
        
    }];
    
    //  添加collection
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    ZCollectionView *collectionView = [[ZCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];;
    
    
    self.collectionView = collectionView;
    
    [self addSubview:collectionView];
    
    //  添加约束
    [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(textLabel.mas_bottom).offset(8);
        make.leading.offset(10);
        
    }];
    
    //  自动约束
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        
//        self.constraint = make.bottom.equalTo(collectionView.mas_bottom);
    }];
}

#pragma mark
#pragma mark - 重写set方法
- (void)setHomeViewModel:(ZHomeModelViewModel *)homeViewModel{
    
    _homeViewModel = homeViewModel;
    
    self.labContent.text = homeViewModel.userModel.retweeted_status.text;
    
//    self.collectionView.picModel = homeViewModel.userModel.retweeted_status.pic_urls;
    
    NSInteger count = homeViewModel.userModel.retweeted_status.pic_urls.count;
    
    [self.constraint deactivate];
    
    if (count == 0) {
        
        self.collectionView.hidden = YES;
        
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.bottom.equalTo(self.labContent.mas_bottom);
        }];
        
        
        
    }else{
        
        
        self.collectionView.hidden = NO;
        //  图片
        self.collectionView.picModel = homeViewModel.userModel.retweeted_status.pic_urls;
        
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.bottom.equalTo(self.collectionView.mas_bottom);
            
        }];
        
    }

}

@end
